"use strict";
const common_vendor = require("../common/vendor.js");
const store_manualThemeStore = require("../store/manualThemeStore.js");
const composables_types_theme = require("./types/theme.js");
function useManualTheme() {
  const store = store_manualThemeStore.useManualThemeStore();
  const showThemeColorSheet = common_vendor.ref(false);
  function toggleTheme(mode) {
    store.toggleTheme(mode);
  }
  function openThemeColorPicker() {
    showThemeColorSheet.value = true;
  }
  function closeThemeColorPicker() {
    showThemeColorSheet.value = false;
  }
  function selectThemeColor(option) {
    store.setCurrentThemeColor(option);
    closeThemeColorPicker();
  }
  function initTheme() {
    store.initTheme();
  }
  common_vendor.onBeforeMount(() => {
    initTheme();
    if (typeof common_vendor.index !== "undefined" && common_vendor.index.onThemeChange) {
      common_vendor.index.onThemeChange((res) => {
        if (store.followSystem) {
          toggleTheme(res.theme);
        }
      });
    }
  });
  common_vendor.onShow(() => {
    store.setNavigationBarColor();
  });
  common_vendor.onUnmounted(() => {
    if (typeof common_vendor.index !== "undefined" && common_vendor.index.offThemeChange) {
      common_vendor.index.offThemeChange((res) => {
        if (store.followSystem) {
          toggleTheme(res.theme);
        }
      });
    }
  });
  return {
    // 状态
    theme: common_vendor.computed(() => store.theme),
    isDark: common_vendor.computed(() => store.isDark),
    followSystem: common_vendor.computed(() => store.followSystem),
    hasUserSet: common_vendor.computed(() => store.hasUserSet),
    currentThemeColor: common_vendor.computed(() => store.currentThemeColor),
    themeVars: common_vendor.computed(() => store.themeVars),
    showThemeColorSheet,
    // 常量
    themeColorOptions: composables_types_theme.themeColorOptions,
    // 方法
    initTheme,
    toggleTheme,
    setFollowSystem: store.setFollowSystem,
    openThemeColorPicker,
    closeThemeColorPicker,
    selectThemeColor
  };
}
exports.useManualTheme = useManualTheme;
